package com.graphics.enginedemo.simpledemo;

import android.content.Context;
import android.view.MotionEvent;

import com.graphics.engine.graphics.GLCanvas;
import com.graphics.engine.graphics.GLDrawable;
import com.graphics.engine.view.GLView;
import com.graphics.enginedemo.R;

/**
 * <br>
 * 类描述: <br>
 * 详细描述: <br>
 * <b>Author sichard</b> <br>
 * <b>Date 2016/7/12</b> <br>
 * project Android-Road-OS
 */
public class GLViewSimpleDemo extends GLView {


    GLDrawable mDrawable;

    public GLViewSimpleDemo(Context context) {
        super(context);
        mDrawable = GLDrawable.getDrawable(getResources(), R.drawable.preview_panel);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        mDrawable.setBounds(0, 0, (int) (w * 0.75f), (int) (h * 0.75f));
    }

    float t; // CHECKSTYLE IGNORE

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        t = (event.getX() - 100) / (getWidth() - 200);
        t = Math.max(0, Math.min(t, 1));
        invalidate();
        return true;
    }

    @Override
    protected void onDraw(GLCanvas canvas) {
        canvas.translate(getWidth() / 2, getHeight() / 2);

        int w = mDrawable.getBounds().width();
        int h = mDrawable.getBounds().height();

        canvas.translate(-w / 2, -h / 2);
        mDrawable.draw(canvas);
        //
        // canvas.translate(w / 2, 0);
        // canvas.rotateAxisAngle(180, 0, 1, 0);
        // canvas.translate(-w / 2, 0);
        mDrawable.draw(canvas);
    }

}


